<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% try { %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<HTML>
<HEAD>
<title>Select Country and Region</title>
<STYLE type="text/css">
USERDETAILS.TABLE {
	margin: 20px;
}

amexLogo.TABLE {
	margin: 20px;
	border: 5px;
}

#hline.hr {
	vertical-align: top;
}

#dropShadow.input {
	filter: DropShadow(Color = #EEEE66, OffX = 5, OffY = 5);
}
</STYLE>
<script type="text/javascript">
	function deleteRow(tableID) {
		var Parent = document.getElementById(tableID);

		while (Parent.hasChildNodes()) {
			Parent.removeChild(Parent.firstChild);
		}
	}

	function showRegion() {
		var cntryNames = "";

		//var table = document.getElementById("CountryDetails");
		//var rowCount = table.rows.length;

		for ( var count = 0; count < document.CountryRegionForm.checkCntry.length; count++) {
			if (document.CountryRegionForm.checkCntry[count].checked) {
				cntryNames += document.CountryRegionForm.checkCntry[count].value + ",";
			}
		}

		//alert('cntryNames='+cntryNames);
		deleteRow('RegionDetails');
		addRow('RegionDetails');
	}

	function addRow(tableID) {

		var table = document.getElementById(tableID);

		var rowCount = table.rows.length;
		var row = table.insertRow(rowCount++);

		var cell1 = row.insertCell(0);
		var element1 = document.createElement("input");
		element1.type = "checkbox";
		cell1.appendChild(element1);

		var cell2 = row.insertCell(1);
		cell2.innerHTML = "<FONT size='2' face='Arial'><label id='l2'>Mumbai</label></font>";

		/*var cell3 = row.insertCell(2);
		var element2 = document.createElement("input");
		element2.type = "text";	            
		cell3.appendChild(element2);
		 */

		row = table.insertRow(rowCount++);

		cell1 = row.insertCell(0);
		element1 = document.createElement("input");
		element1.type = "checkbox";
		cell1.appendChild(element1);

		cell2 = row.insertCell(1);
		cell2.innerHTML = "<FONT size='2' face='Arial'><label id='l2'>Delhi</label></font>";
	}

	function SubmitForm() {
		var cntryId = "";
		var regnId = "";
		for ( var count = 0; count < document.CountryRegionForm.checkCntry.length; count++) {
			if (document.CountryRegionForm.checkCntry[count].checked) {
				cntryId += document.CountryRegionForm.checkCntry[count].value
						+ ","; //append GEO_AREA_ID
			}
		}

		for (count = 0; count < document.CountryRegionForm.checkRegn.length; count++) {
			if (document.CountryRegionForm.checkRegn[count].checked) {
				regnId += document.CountryRegionForm.checkRegn[count].value
						+ ","; //append GEO_AREA_ID
			}
		}

		cntryId = cntryId.substring(0, cntryId.length - 1);
		regnId = regnId.substring(0, regnId.length - 1);

		window.opener.document.UserCriteriaForm.cntryId.value = cntryId;
		window.opener.document.UserCriteriaForm.regnId.value = regnId;
		//document.CountryRegionForm.cntryId.value=cntryId;
		//document.CountryRegionForm.regnId.value=regnId;
		//alert("Final::cntryId="+window.opener.document.UserCriteriaForm.cntryId.value+",regnId="+window.opener.document.UserCriteriaForm.regnId.value);
		//document.CountryRegionForm.action="/giid/SearchGeoAreaResults.do?action=editGeoAreaDetails";
		//document.CountryRegionForm.submit();

		//session.removeAttribute("GeoCountry");
		//session.removeAttribute("GeoRegion");
		window.close();
	}
</script>
<%@ taglib uri="/webUtilTL.tld" prefix="web"%>
<link type="text/css" rel="stylesheet"
	href="/giid/style/_custom/dhtmlgoodies_calendar.css?random=20051112"
	media="screen"></LINK>
<!--<script language="JavaScript" src="gen_validatorv31.js" type="text/javascript"></script> -->
<SCRIPT type="text/javascript"
	src="/giid/javascript/customized/dhtmlgoodies_calendar.js?random=20060118"></script>
<SCRIPT type="text/javascript"
	src="/giid/javascript/customized/toggle.js"></script>
<%@ page
	import="java.util.Map,java.util.HashMap,java.util.TreeMap,java.util.Iterator,com.microstrategy.utils.MSTRCheckedException,com.microstrategy.web.beans.*,com.microstrategy.web.objects.*,com.microstrategy.web.objects.admin.users.*,java.io.PrintStream,java.util.ArrayList,java.util.Date"%>
</HEAD>
<%
	TreeMap hashCountry = (TreeMap) session.getAttribute("GeoCountry");
	hashCountry = new TreeMap();
	
	TreeMap hashRegion = (TreeMap) session.getAttribute("GeoRegion");
	hashRegion = new TreeMap();
	
	ArrayList arrListGeoAreaDetails = (ArrayList) session.getAttribute("GeoAreaDetails");
	arrListGeoAreaDetails = new ArrayList();

	String strChecked = "";
	
%>

<BODY leftmargin="0px" topmargin="0px" marginwidth="0px"
	marginheight="0px">

	<form name="CountryRegionForm" method="post"
		action="/giid/SubmitApproval.do">
		<BR>
		<BR>
		<div class="scroll" style="overflow: auto; width: 450; height: 350;">
			<TABLE class="CountryRegionDetails" border="0">
				<TR align="left" valign="middle">
					<TD valign="top" align="left" width="304"><FONT size="2"
						face="Arial"><label id='l2'><B>Select Country</B></label></FONT></TD>
					<TD valign="top" align="left" width="304"><FONT size="2"
						face="Arial"><label id='l2'><B>Select Region</B></label></FONT></TD>
				</TR>

				<TR>
					<TD valign="top">
						<TABLE class="CountryDetails">

							<%
								Iterator iterator = hashCountry.keySet().iterator();
								String key = null;
								String value = null;
								String temp = "";
								while (iterator.hasNext()) {
									key = (String) iterator.next();
									value = (String) hashCountry.get(key);
									temp = key;
									key = value;
									value = temp;
									for (int count = 0; count < arrListGeoAreaDetails.size(); count++) {
										if (key.equals((String) arrListGeoAreaDetails.get(count))) {
											strChecked = "checked";
											break;
										}
									}
							%>

							<TR align="left" valign="middle">
								<TD valign="top" align="left"><input type="checkbox"
									name="checkCntry" value="<%=key%>" <%=strChecked%>></TD>
								<TD valign="top" align="left"><FONT size="2" face="Arial"><%=value%></FONT></TD>
							</TR>
							<%
								strChecked = "";//flush val 
								}//While ends
							%>

						</TABLE>
					</TD>
					<TD valign="top">
						<TABLE class="RegionDetails" id="RegionDetails">
							<%
								iterator = hashRegion.keySet().iterator();

								while (iterator.hasNext()) {
									key = (String) iterator.next();
									value = (String) hashRegion.get(key);
									temp = key;
									key = value;
									value = temp;
									for (int count = 0; count < arrListGeoAreaDetails.size(); count++) {
										if (key.equals((String) arrListGeoAreaDetails.get(count))) {
											strChecked = "checked";
											break;
										}
									}
							%>

							<TR align="left" valign="middle">
								<TD valign="top" align="left"><input type="checkbox"
									name="checkRegn" value="<%=key%>" <%=strChecked%>></TD>
								<TD valign="top" align="left"><FONT size="2" face="Arial"><%=value%></FONT></TD>
							</TR>
							<%
								strChecked = "";//flush val 
								}//While ends
							%>

						</TABLE>
					</TD>
				</TR>
			</TABLE>
		</div>

		<TABLE>
			<TR align="left" valign="middle">
				<TD align="left" valign="middle">
					<!--<input name="DisplayRegion" type="Button"  value="DisplayRegion" onClick="showRegion()"/>&nbsp;&nbsp;&nbsp;-->
					<input name="Submit" type="Button" value="OK"
					onclick="SubmitForm()" />&nbsp;&nbsp;&nbsp; <input name="Cancel"
					type="Button" value="Cancel" onclick="window.close();" />
				</TD>
			</TR>
		</TABLE>


		<!--<input type="hidden" name="cntryId" value="">
<input type="hidden" name="regnId" value="">
-->

	</form>
</BODY>
</HTML>
<%
} catch(Throwable t) {
	t.printStackTrace();
}
%>